package com.cjm.algorithm.tree;

import com.cjm.algorithm.TreeNode;

public class Ti112 {
    public static void main(String[] args) {

    }

    public boolean hasPathSum(TreeNode root, int targetSum) {
        if (root==null) return false;
        return method112(root, 0, targetSum);
    }

    private boolean method112(TreeNode root, int currentSum, int targetSum) {
        if (root == null) return false;
        currentSum+=root.val;
        if (root.left == null && root.right == null && targetSum == currentSum) {
            return true;
        }

        return method112(root.left, currentSum, targetSum) || method112(root.right, currentSum, targetSum);
    }
}
